SentenceListLoader=function(){
	this.inited=false;
	this.appVM=null;
	this.options={};
}

SentenceListLoader.defValue={
	appVMConfig:{
		el:"#sentence-list-app",
		data:{
			sentenceList:[],
		}
	},
	itemContentEl:null,
	itemEl:".mui-table-view-cell",
	itemTapFunc:function(loader,tappedEle){
		loader.toDetailPage(tappedEle);
	},
	loadParam:{
		pageNo:1,
		pageSize:20,
	},
	loadOverCallback:function(){}
}

SentenceListLoader.prototype.init=function(opts){
	var that=this;
	if(!this.inited){
		this.options=$.extend(true,{},SentenceListLoader.defValue,opts);
		this.appVM=new Vue(this.options.appVMConfig);
		if(this.options.itemContentEl && this.options.itemTapFunc){
			$(this.options.itemContentEl).on('tap',this.options.itemEl,function(){
				//第二个参数为当前tap的元素
				that.options.itemTapFunc(that,this);
			});
		}
	}
	this.inited=true;
}

//
SentenceListLoader.prototype.getLoadParam=function(){
	return this.options.loadParam;
}
//
SentenceListLoader.prototype.getOptions=function(){
	return this.options;
}
//
SentenceListLoader.prototype.loadSentenceList=function(){
	var that=this;
	var appVMConfigData=this.options.appVMConfig.data;
	var url=getShiciServiceHost()+'/shici/sentence/list';
	muiAjaxGetJsonData({
		url:url,
		data:that.options.loadParam,
		callback:function(data){
			if(data.entry){
				if(data.entry.dataList && data.entry.dataList.length>0){
					mui.each(data.entry.dataList,function(index,itemInfo){
					   itemInfo.name=itemInfo.name.trim();
					   appVMConfigData.sentenceList.push(itemInfo);
					});
				}
				that.options.loadOverCallback(that,data);
			}
		},
	});
}
//
SentenceListLoader.prototype.emptyShiwenList=function(){
	var appVMConfigData=this.options.appVMConfig.data;
	appVMConfigData.sentenceList = [];
}
//
SentenceListLoader.prototype.toDetailPage=function(tappedEle){
	var index=$(tappedEle).attr('index');
	var dataList=this.options.appVMConfig.data.sentenceList;
	var indexData=dataList[index];
	var infoId=indexData.id;
	console.info("sentenceId="+infoId);
	mui.openWindow({
		url: 'sentenceRandomCard.html?id=' + infoId,
		id: 'sentenceRandomCard.html-id-' + infoId,
		extras: {
			infoId: infoId,
			//sentence:JSON.stringify(currentSentence)
		}
	});
}